package avicit.bdp.dds.common.utils;


/**
 *  utility methods for validating input
 *
 */
public final class Preconditions {

    private Preconditions() {}

    /**
     * if obj is null will throw NPE
     *
     * @param obj obj
     * @param <T> T
     * @return T
     */
    public static <T> T checkNotNull(T obj) {
        if (obj == null) {
            throw new NullPointerException();
        }
        return obj;
    }

    /**
     * if obj is null will throw NullPointerException with error message
     * @param obj obj
     * @param errorMsg error message
     * @param <T> T
     * @return T
     */
    public static <T> T checkNotNull(T obj,  String errorMsg) {
        if (obj == null) {
            throw new NullPointerException(errorMsg);
        }
        return obj;
    }


    /**
     * if condition is false will throw an IllegalArgumentException with the given message
     *
     * @param condition condition
     * @param errorMsg  error message
     *
     * @throws IllegalArgumentException Thrown, if the condition is violated.
     */
    public static void checkArgument(boolean condition,  Object errorMsg) {
        if (!condition) {
            throw new IllegalArgumentException(String.valueOf(errorMsg));
        }
    }


}
